﻿
        <!-- /. NAV SIDE  -->
        <div id="page-wrapper">
            <div id="page-inner">
                <div class="panel panel-default">
                        <div class="panel-heading">
                          分类列表
                        </div>
                        <div class="panel-body">
                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover">
                                 <thead>
                                    
                                        <tr>
                                            <th>id</th>
                                            <th>名称</th>
                                            <th>pid</th>
                                           
                                            <th>操作</th>
                                        </tr>
                                  
                                   </thead>
                                   
                                    <tbody>
                                  
                                    <?php foreach($cate as $v){?> 

                                    
                                        <tr class="cchange " level="1" pid="<?php echo $v['pid']?>">
                                            <th><?php echo $v['id']?></th>
                                             <th><a id="<?php echo $v['id']?>" class="btn btn-info jia">+</a> <?php echo $v['name']?></th>
                                              <th><?php echo $v['pid']?></th>

                                       
                                            <th><a href="index.php?c=cate&a=adxit&admin=1&id=<?php echo $v['id'];?>" class="btn btn-info">
                                               <i class="fa fa-pencil-square-o"></i>
                                               编辑</a> 
                                               <a href="index.php?c=cate&a=del&admin=1&id=<?php echo $v['id'];?>""
                                               onclick="return confirm('确定要删除？')" class="btn btn-danger lac ">
                                               <i class="fa fa-trash-o"></i>
                                               删除</a>      
                                            </th>
                                        </tr>
                                  
                                   
                                    <?php }?>
                                    </tbody>
                                </table>
                                
                            <hr />
                          
                            </div>
                        </div>
                    </div>

            </div>
            <!-- /. PAGE INNER  -->
        </div>
        <!-- /. PAGE WRAPPER  -->
    </div>
    <!-- /. WRAPPER  -->
<script src="resources/assets/js/jquery-1.10.2.js"></script>
<script type="text/javascript">
// $(function(){
//   $('.lac').click(function(){
//     var url = $(this).attr('href');
  

//       $.ajax({
//         type: 'get',
//         // 发送的请求类型 get/post
//         url: url,
//         // 请求的路径
      
//         success: function(json) {
//           console.log(json);
//           if(json>0){

//             if(confirm('你所要删除的内容存在子级确定要删除吗？')){

//               location.href=url;
//             }
//             return false;

//           }
//         }
// })
//        return false;
//  })


$(function(){
$("tbody").on('click','.jia',function(){  
  var left=0;

  var id=$(this).attr('id');
  var obj=$(this);
  var tr_obj=$(obj).parent().parent();
  var pid=tr_obj.attr('pid');
  var index=$('tr[pid='+pid+']');
  var len=$('tr[pid='+pid+']').length-1;

if('+'==$(this).text()){
var level=parseInt(tr_obj.attr('level'));

left=level*60;
level++;

  $(this).text('-')
  $.ajax({
      type:'get', 
      url:'index.php?c=cate&a=list&admin=1&id='+id,
      dataType:'json',
 success: function(json){

    html='';
    for(i in json){
    html+='<tr class="cchange " pid="'+id+'" level="'+level+'">';
    html+='<th>'+json[i].id+'</th>';
    html+='<th style="padding-left:'+left+'px"><a class="btn btn-info jia" id='+json[i].id+'>+</a>'+json[i].name+'</th>';
    html+='<th>'+json[i].pid+'</th>';
    html+='<th><a href="index.php?c=cate&a=adxit&admin=1&id='+json[i].id+'" class="btn btn-info">';
    html+='<i class="fa fa-pencil-square-o"></i>编辑</a>';                       
    html+='<a href="index.php?c=cate&a=del&admin=1&id='+json[i].id+'" class="btn btn-danger ">';
    html+='<i class="fa fa-trash-o"></i>删除</a>';      
    html+=' </th>';
    html+='</tr>';
    
     

      

    }
    html+='<tr pid='+json[i].pid+' style="display:none"></tr>';
    tr_obj.after(html);

 
 } 

  })
  }else{
       $(this).text('+');

       var pid=tr_obj.attr('pid');
       //抓取当前操作按钮的父级tr标签，从该标签开始查找到下一个符合pid=0(nextUntil('tr[pid=0]'))的tr标签，然后把这两个tr之前的内容删除remove()
       
       tr_obj.nextUntil('tr[pid='+pid+']').remove();
      
    }


})  


})






</script>
  